/*
 * $Id: StepTimeMessageConverter.java,v 1.3 2009/07/24 18:28:02 oliver Exp $
 *
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 *
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */

/**
 * 
 */
package com.ge.healthcare.autosc.common.message.converter;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;

import com.ge.healthcare.autosc.common.database.pojo.HstStepTime;

/**
 * @author 212042764
 * 
 */
public class StepTimeMessageConverter implements MessageConverter {
	public StepTimeMessageConverter() {
	}

	public HstStepTime fromMessage(Message message) throws JMSException,
			MessageConversionException {
		if (!(message instanceof ObjectMessage)) {
			throw new MessageConversionException(
					"Message isn't object message, message:" + message);
		}
		Object object = ((ObjectMessage) message).getObject();
		if (!(object instanceof HstStepTime)) {
			throw new MessageConversionException(
					"Object isn't subclass of Step Time, object:" + object);
		}
		return (HstStepTime) object;
	}

	public Message toMessage(Object object, Session session)
			throws JMSException, MessageConversionException {
		if (!(object instanceof HstStepTime)) {
			throw new MessageConversionException(
					"Object isn't an instance of HstStepTime, object:" + object);
		}
		HstStepTime stepTime = (HstStepTime) object;
		ObjectMessage message = session.createObjectMessage();
		message.setObject(stepTime);
		return message;
	}

}
